from core.user import * 
from django.template import Context, loader, RequestContext

@browser_prefix
def View(request,sname,path):
   try:
      service = ServiceCore.objects.get(name=sname) 
      gallery_t = loader.get_template('gallery/gallery.html')
      args = path.split("/")
      gallery = args[0];
      icon = "";
      cmd = "";
      if(len(args)>1):
        icon = args[1]
      if(request.REQUEST.has_key('cmd')):
        cmd = request.REQUEST['cmd']
      usetmp = False;
      if(request.REQUEST.has_key('usetmp') and request.REQUEST['usetmp'] == 'true'):
        usetmp = True 
      c = RequestContext (request,{'SERVICE':service,'GALLERY':gallery,'ICON':icon,'CMD':cmd,'USETMP':usetmp})
      response = HttpResponse(gallery_t.render(c),mimetype = "text/html")
      return response
   except ServiceCore.DoesNotExist:
      return HttpResponse("Service Does Not Exist")
    
def Main(request):
   items = core.Info.objects.all[:12]
   gallery_t = loader.get_template('gallery/main.html')
   c = RequestContext (request,{'ITEMS':items})
   response = HttpResponse(gallery_t.render(c),mimetype = "text/html")
   return response
 
